package com.sky.controller.admin;

import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@Api(tags = "商家端店铺")
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    private static final String shopStatus="shop_status";
    /**
     * 设置店铺的应业状态
     * @return
     */
    @ApiOperation("设置店铺状态")
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status){
        log.info("设置店铺的状态为:{}",status== StatusConstant.ENABLE?"营业中":"打烊中");
        redisTemplate.opsForValue().set(shopStatus,status);
        return Result.success();
    }


    /**
     * 获取店铺状态
     * @return
     */
    @ApiOperation("获取店铺的状态")
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        Integer status= (Integer) redisTemplate.opsForValue().get(shopStatus);
        log.info("获取店铺状态:{}", Objects.equals(status, StatusConstant.ENABLE) ?"营业中":"打烊中");
        return Result.success(status);
    }


}
